<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/normalize.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <style>

    </style>
</head>

<body class="ares-p">
<table class="layui-hide" id="table" lay-filter="table"></table>

<script type="text/html" id="tableBar">
    {{#  if(d.status == 1){ }}
    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="check">查看</button>
    <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="redo">重新评估</button>
    {{# } else{ }}
    {{#  if(d.medical.id == d.currentProfileId){ }}
    <button class="layui-btn layui-btn-xs" lay-event="do">评估</button>
    {{#  } }}
    {{#  } }}
</script>
<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
	layui.use(['table', 'utils','dateFilters', 'mandyServices', 'store', 'qs'], function (table, utils, dateFilters,  mandyServices, store, qs) {
		var queryParams = qs.parse(location.search.substr(1)),
			profileId = store.session.get('profileId');

		getList(queryParams.patientId);


		function getList(patientId) {
			mandyServices.mandy_get_gauge_record_by_patient_id(null, patientId).then(function (res) {
				var data = res.data,
					list = data.gauge_record_list == null ? [] : data.gauge_record_list;
                $.each(list,function (index,item) {
                    item.currentProfileId = profileId;
                })
                console.log(list)
				table.render({
					elem: '#table',
                    limit: list.length + 1,
					data: list,
					cellMinWidth: 80,
					cols: [[
						{title: '病种', templet: '<span>{{d.prescription_item.disease.name}}</span>'},
						{title: '评估表', templet: '<span>{{d.gauge.name}}</span>'},
						{title: '评估人', templet: '<span>{{d.medical.name}}</span>'},
						{title: '创建时间', templet: '<span>{{d.create_time}}</span>'},
						{
							title: '完成时间', width: 150,
							templet: function (d) {
								return dateFilters.dateTimeFormat(d.finish_time);
							}
						},
						{title: '操作', fixed: 'right', width: 120, templet: '#tableBar'}
					]]
				});
				table.on('tool(table)', function (obj) {
					var data = obj.data,
						prescriptionItemId = data.prescription_item.id;
					switch (obj.event) {
						case 'check':
							openGauge(prescriptionItemId);
							break;
						case 'redo':
							reEvaluation(prescriptionItemId);
							break;
						case 'do':
							openGauge(prescriptionItemId);
							break;
					};
				});
			});
		}

		function openGauge(prcpItemId) {
			var query = {
				prcpItemId: prcpItemId
            };
			utils.pushTopRoute('/evaluation/gauge', query)
            utils.layer.closeAll('iframe');
		}

		function reEvaluation(prescriptionItemId) {
			var query = {
				prcpItemId: prescriptionItemId,
				type: 're_evaluation'
			};
			utils.pushTopRoute('/evaluation/gauge', query)
            utils.layer.closeAll('iframe');
		}
	})
</script>
</body>
</html>
